package com.shop.cereshop.admin.controller.sos;

import com.shop.cereshop.admin.annotation.NoRepeatSubmit;
import com.shop.cereshop.admin.annotation.NoRepeatWebLog;
import com.shop.cereshop.admin.param.sos.SosPhoneIdParam;
import com.shop.cereshop.admin.param.sos.SosPhoneQueryParam;
import com.shop.cereshop.admin.param.sos.SosPhoneSaveParam;
import com.shop.cereshop.admin.param.sos.SosPhoneUpdateParam;
import com.shop.cereshop.admin.service.sos.CereSosPhoneService;
import com.shop.cereshop.commons.domain.common.Page;
import com.shop.cereshop.commons.domain.sos.CereSosPhone;
import com.shop.cereshop.commons.domain.user.CerePlatformUser;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 一键急救电话管理
 */
@RestController
@RequestMapping("sosPhone")
@Slf4j(topic = "SosPhoneController")
@Api(value = "一键急救电话管理", tags = "一键急救电话管理")
public class SosPhoneController {

    @Autowired
    private CereSosPhoneService cereSosPhoneService;

    /**
     * 新增急救电话
     */
    @PostMapping("save")
    @NoRepeatSubmit
    @NoRepeatWebLog
    @ApiOperation(value = "新增急救电话")
    public Result<Void> save(@RequestBody @Validated SosPhoneSaveParam param, HttpServletRequest request) throws CoBusinessException {
        CerePlatformUser user = (CerePlatformUser) request.getAttribute("user");
        cereSosPhoneService.save(param, user);
        return Result.success();
    }

    /**
     * 修改急救电话
     */
    @PostMapping("update")
    @NoRepeatSubmit
    @NoRepeatWebLog
    @ApiOperation(value = "修改急救电话")
    public Result<Void> update(@RequestBody @Validated SosPhoneUpdateParam param, HttpServletRequest request) throws CoBusinessException {
        CerePlatformUser user = (CerePlatformUser) request.getAttribute("user");
        cereSosPhoneService.update(param, user);
        return Result.success();
    }

    /**
     * 删除急救电话
     */
    @PostMapping("delete")
    @NoRepeatSubmit
    @NoRepeatWebLog
    @ApiOperation(value = "删除急救电话")
    public Result<Void> delete(@RequestBody @Validated SosPhoneIdParam param, HttpServletRequest request) throws CoBusinessException {
        CerePlatformUser user = (CerePlatformUser) request.getAttribute("user");
        cereSosPhoneService.delete(param, user);
        return Result.success();
    }

    /**
     * 急救电话详情
     */
    @PostMapping("detail")
    @ApiOperation(value = "查询急救电话详情")
    public Result<CereSosPhone> detail(@RequestBody @Validated SosPhoneIdParam param) throws CoBusinessException {
        CereSosPhone data = cereSosPhoneService.detail(param.getId());
        return Result.success(data);
    }

    /**
     * 急救电话分页
     */
    @PostMapping("page")
    @ApiOperation(value = "分页查询急救电话")
    public Result<Page<CereSosPhone>> page(@RequestBody SosPhoneQueryParam param) throws CoBusinessException {
        Page<CereSosPhone> page = cereSosPhoneService.page(param);
        return Result.success(page);
    }
}

